layui.use(["jquery","upload"],function () {
    var $ = layui.jquery;
    var upload = layui.upload;
    var allowClickRuKu = false;
    var imageName;
    var carInImgUpload = upload.render({
        elem: '#carInImageUploadBtn' //绑定元素
        ,url: '/uploadImg/' //上传接口
        ,done: function(res, index, upload){
            //上传完毕回调
            console.info(res);
            console.info(upload);
            console.info(index);
            console.info("success");
            if(res.carNo[1] === "-1"){
                layer.alert("识别失败，请手动输入车牌号和车辆类型")
            }
            $("#carId").val(res.carNo[1]);
            $("#carType").val(res.carNo[2]);
            $("#carInShow").attr("src","..//img//carImg//"+res.carNo[0]);
            imageName=res.carNo[0];
            allowClickRuKu = true;
        }
        ,error: function(index, upload){
            layer.alert("服务器出错")
        }
        ,accept: 'images'
        ,acceptMime: 'image/*'
    });
    $("#carInBtn").on("click",function () {
        var carId = $("#carId").val();
        var carType = $("#carType").val();
        if (allowClickRuKu){
            if(carId.length<5||(carType!=="大型车")&&(carType!=="小型车")){
                layer.alert("请输入车牌号和车类型");
            }else{
                $.ajax({
                    type:"post",
                    url:"/carIn",
                    data:{
                        carId:carId,
                        carType:carType,
                        image:imageName
                    },
                    success: function (res) {
                        $("#carInShow").attr("src","..//img//move.gif");
                        layer.msg("入库成功");
                    },
                    error: function (res) {
                        
                    }
                })
            }


        }else{
            layer.alert("当前状态不允许点击入库")
        }

    })
});